from django.db import models

# Create your models here.
class Category(models.Model):
    name=models.CharField(verbose_name="分类名称",max_length=20)
    create_time=models.DateTimeField(verbose_name="创建时间",auto_now_add=True)
    update_time = models.DateTimeField(verbose_name="更新时间", auto_now=True)

    def __str__(self):
        return  self.name

    #user_category
    class Meta:
        # db_table="category"#实际在数据库里面创建的表名
        verbose_name="分类表"
        verbose_name_plural=verbose_name


class Article(models.Model):
    title=models.CharField(verbose_name="文章标题",max_length=50)
    desc=models.CharField(verbose_name="文章描述",max_length=100)#char类型最长255
    content=models.TextField(verbose_name="文章内容")#文本类型，不需要加长度
    img=models.ImageField(verbose_name="文章图片",null=True,blank=True,upload_to='./static')
    show_count=models.IntegerField(verbose_name="查看次数",default=0)
    category=models.ForeignKey(Category,on_delete=models.PROTECT,verbose_name="分类")
    tag=models.CharField(verbose_name="标签",blank=True,max_length=100)
    # models.DO_NOTHING什么也不做
    # models.CASCADE级联
    # models.SET_DEFAULT设置一个默认值
    # models.PROTECT受保护的
    create_time = models.DateTimeField(verbose_name="创建时间", auto_now_add=True)
    update_time = models.DateTimeField(verbose_name="更新时间", auto_now=True)

    def __str__(self):
        return  self.title

    class Meta:
        db_table="article"
        verbose_name="文章"
        verbose_name_plural = verbose_name

class User(models.Model):
    username=models.CharField(verbose_name="用户名",max_length=10,unique=True)
    password = models.CharField(verbose_name="密码", max_length=32)

    def __str__(self):
        return self.username

    class Mata:
        db_table = "user"
        verbose_name = "用户"
        verbose_name_plural = verbose_name
